﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
//using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using JCNT.DAL;
//using JCNT.NoteWeb.Pub;
//using System.Xml.Linq;

namespace JCNT.NoteWeb.Web
{
    public partial class Tree : System.Web.UI.Page
    {
        CSQLServer ado1 = new CSQLServer();
        CTree tree = new CTree();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //if (Session["login"] != null)
                //{
                    //Fill_Tree();
                    ref_Tree();
                //}
                //else
                //{
                //    //跳转到登入页面                
                //    Response.Write("<script>alert('您的登录信息过期，请重新登录！');</script>");
                //    Response.Write("<script>window.opener = null;parent.close();window.open ('login.aspx');</script>");
                //}

            }
        }

        public void ref_Tree()
        {
            TreeView1.Nodes.Clear();
            tree.fillTree(TreeView1, null, "0");

            if (Session["nodeID"] != null)
            {
                string ID = Session["nodeID"].ToString();
                foreach (TreeNode node1 in TreeView1.Nodes)
                {
                    if (node1.Value == ID)
                    {
                        TreeNode node2 = node1;
                        while (node2.Depth > 0)
                        {
                            node2.Parent.Expand();
                            //node2.Parent.ImageUrl = "images/jian.jpg";
                            node2 = (TreeNode)node2.Parent;

                        }
                        node1.Expand();
                        //node1.ImageUrl = "images/jian.jpg";
                    }
                    else
                    {
                        findNode(node1, ID);
                    }
                }

            }
        }

        public void findNode(TreeNode nodes, string ID)
        {
            foreach (TreeNode node1 in nodes.ChildNodes)
            {

                if (node1.Value == ID)
                {
                    TreeNode node2 = node1;
                    while (node2.Depth > 0)
                    {
                        node2.Parent.Expand();
                        //node2.Parent.ImageUrl = "images/jian.jpg";
                        node2 = (TreeNode)node2.Parent;
                    }
                    node1.Expand();
                    //node1.ImageUrl = "images/jian.jpg";
                }
                else
                {
                    findNode(node1, ID);
                }
            }
        }

        protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
        {
            Session["nodeID"] = TreeView1.SelectedNode.Text;
        }

    }
}
